Skip to content

Runs reproduce a bug first, read the files' history, account for dependents, ask early with a default, and prove their tests fail without the change - #650

Closed
nambok wants to merge 1 commit into
mainfrom
coder-habits
Closed

nambok wants to merge 1 commit into
mainfrom
coder-habits

Conversation

@nambok

@nambok nambok commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator

Summary

A run now does what a careful engineer does before and while writing code, and the worker checks each habit in code instead of trusting a prompt.

  • Reproduce first. A bug's plan names the test that fails on the code as it is, and the worker moves that test's task to the top of the checklist so it is written and committed before the fix. When no failing test can be written (no test setup, a pure configuration change) the plan says why and names the next best proof, and the pull request carries that instead.
  • Tests that mean something. After the build, each new or changed test file is run in the sandbox twice: on the branch, and on the base with only the test files added (the fix taken out). A test that passes both ways, a bug's test that cannot build on the base, and a test that fails with the change all go back to the coder in a fix round. The pull request shows the failing result and the passing result.
  • Read the history. The worker itself reads the commits of the files the plan modifies and hands the planner what it found. A revert on one of them must be answered by name (its commit or pull request) before the plan stands.
  • Know who it affects. The worker asks the code graph what the planned files reach and searches the team's other connected repositories for each name the plan says it changes. Every dependent is updated by a task or called safe with the reason, and the pull request lists them either way.
  • Ask early. A doubt that changes what gets built is asked at planning time with a proposed default. The default is planned and built while the question is open on the ticket; the run does not wait.
  • Stay in scope. A changed file that is no task of the plan (and no test, lockfile, generated output or planned dependent) is restored by the coder or carries its reason in the pull request.

Splitting one large change into several pull requests is not in this change. A run owns one branch and one pull request per repository today, so splitting is a change to the run model and is left for a change of its own.

Changes

New modules in services/worker/src/passes/:

  • habits.rs: the habits object of the plan's decision (repro, area_history, surfaces, no_outside_use, affected, ask_early), read loosely so a malformed habit never costs the plan its decision. Reader::facts reads the planned files' commits (commits_for_path, up to 8 files) and their dependents (Graph::impacted_by, plus a code search of up to 8 other repositories for up to 6 declared names). plan_gaps turns what is missing into send-back lines that carry those facts. keep_open keeps what is still open after the one send-back on the decision and lists an unaccounted use in another repository among those affected, marked as not checked. put_repro_first, fold_questions, design_section and planner_guidance do the rest.
  • habits_check.rs: the check on the open pull request. SandboxBench runs each changed test file as its own step on the branch head and on a temporary branch holding the base plus the test files, side by side. verdict reads the two exit codes and the failing output (a filter that matched no tests is never read as a pass or a failure). outside_plan, not_updated, blocking, fix_feedback, open_findings and section produce the fix round, the Open items and the description's section. The check keeps its rounds and result in the run's ledger like the other checks, and asks once for a step of its own when the sandbox runs would not fit in the time left.
  • incidents/ah_coder_habits.rs and a row in docs/incidents.md.

Shared files touched, each minimally:

  • fix_location.rs: one field on FixDecision (habits) and the planner guidance gains the habits section.
  • plan.rs: the facts are read for the draft and their gaps join the existing single send-back; after it, leftovers are kept, the reproducing test is moved first and design.md gains the section; early questions are folded into the decision's questions where the plan is parsed. PLANNER_VERSION is bumped so cached plans are not reused.
  • mod.rs: two module lines; the check is called after the new-feature rules in the single-repository pipeline (with a hand-off at the checks when it needs a step) and in the per-repository path of a run that spans repositories.
  • pr.rs: one field on Proof (habits) and one call in with_checks that places the section.
  • run_guard.rs: the ledger gains the check's record, its last result and whether it has asked for a step.

Not touched: run_checks in implement.rs, the open-items rendering, completeness.rs, proof.rs.

Verification

  • cargo fmt --check --all: clean.
  • cargo clippy --workspace --all-targets -- -D warnings: clean.
  • cargo test --workspace: all pass (common 2088, gateway 902, worker 1643), including the 28 new tests (13 in habits, 11 in habits_check, 4 in incidents::ah_coder_habits).
  • The incident case walks one made-up bug from a plan that names only files, through the send-back with the revert, the other repository's use and the caller, to a first build whose test passes without the fix and whose diff holds a stray file, and on to the description with the failing and passing result. It also checks that the pipeline still calls each piece at its place.
  • Not exercised here: a real planner answering the send-back, the two sandbox runs on a real repository, and the hand-off to a fresh step. The sandbox path reuses test_bug::Runner::run_at and the temporary-branch method test_bug::unit_before_after already uses.

…ndents, ask early with a default, and prove their tests fail without the change

The plan's decision gains a habits object, and the worker holds a run to it
in code.

Before code: a bug's plan names the test that fails on the code as it is
(or why none can, and the next best proof), and that test's task is moved to
the top of the checklist. The worker reads the commits of the files the plan
modifies and what depends on them (the code graph, and a search of the
team's other repositories for each name the plan says it changes); a revert
must be answered by name, and every dependent is updated by a task or called
safe with the reason. A doubt that changes what gets built is asked at
planning time with the default the run builds.

After the build: each new or changed test file runs in the sandbox on the
branch and on the base with only the tests added. A test that passes either
way, a bug's test that cannot build on the base, a changed file outside the
plan with no reason, and a planned dependent left untouched go back to the
coder. The pull request carries the failing and passing result, the history
and who the change affects. The check asks once for a step of its own when
its sandbox runs would not fit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant